shop.header = {
	conf:{city:'', timer: 0,itemWish:'',numItemWish:0,numOrderI:0},
	init:function(){
		shop.header.ads.init();
		shop.header.email.start();
		shop.header.sale.open();
		//shop.header.wishList.build();
		//if(IS_CUSTOMER_LOGIN){
		//	shop.header.quickViewOrder.buildOrder();
		//}
		//shop.header.menuCustomer();
		//shop.header.menuPlaza();
		//fix chieu rong cho menu city
		var w = jQuery('.headerCity').width(),
		l = parseInt(jQuery('.headerCity').css("left")),
		pad = 50;
		jQuery('.subCity').css('width', w-pad);
		jQuery('.regMailButton').css("padding", "0 15px 0 "+(w+l+15)+"px");
		jQuery('body').click(function(){
			jQuery('.ctrlMenu').hide();
		}); 
		//do dac cua RD
		if(RD_TOOLS == 1){
			var rdU = shop.cookie.get('run_rd');
			if(rdU){
				var pos = rdU.indexOf('|');
				var e = rdU.substring(0,pos);
				var i = rdU.substring(pos+1);
				_MA.get_users({
					sitekey	: 'mc',
					email	: e,
					uid	: i
				});
				shop.cookie.set('run_rd',0,-1);
			}
		}
	},
	actionDisplay:{
		showing: 0,
		type: 0,
		wishList: 0,
		order: 0,
		viewMenuUnOrderLike:function(obj, type, event){
			shop.header.actionDisplay.clearMouseClick(event);

			jQuery('.ctrlMenu').hide().attr("id", 0);
			if((shop.header.actionDisplay.showing == 0) || (type != shop.header.actionDisplay.type)){
				shop.header.actionDisplay.showing = 1;
				switch(type){
					case 1:
						shop.header.wishList.viewwishList(function(){
							shop.header.actionDisplay.showMenu(obj);
						});
					break;
					case 2:
						shop.header.quickViewOrder.displayListOrdernew(function(){
							shop.header.actionDisplay.showMenu(obj);
						});
					break;
					default:
						shop.header.actionDisplay.showMenu(obj);
				}
			}else{
				shop.header.actionDisplay.showing = 0;
			}
			shop.header.actionDisplay.type = type;
		},
		showMenu:function(obj){
			jQuery('.ctrlMenu', obj).show().attr("id", 1);
		},
		clearMouseClick:function(event){
			if (event.stopPropagation) {
				event.stopPropagation();   // W3C model
			} else {
				event.cancelBubble = true; // IE model
			}
		}
	},
    quickViewOrder:{
		build1Order:function(i){
			var itemHtml = shop.join
			('<a class="perOrders '+(i.highline==1?'perOrdershLine':'')+'" href="'+i.link+'" lang="'+i.id+'" >')
				(i.payment?'<span class="mTop5" style="color:#32890C;font-weight:bold;font-size:13px;margin-bottom:5px">'+i.payment+'</span>':'')
				('<span class="fl itemBookImg m0 v7img64"><img src="'+i.image+'" width="64" height="64" /></span>')
				('<span class="fl ordersInfo">')
					('<b class="v7titleorderL">'+i.item_title+'</b>')
					('<span class="mTop5" style="font-size:12px;color:#000;line-height:1.6">'+i.status+'</span>')
					('<span class="c"></span>')
				('</span>')
				('<span class="c"></span>')
			('</a>')();
			return itemHtml;
		},
		buildOrderUnuser2:function(cb){
			shop.ajax_popup('act=customer&code=getbuidOrderUnuser',"POST",{},
				function(j){
					if(j.err == 0){
						var item = j.i, itemHtml = '';
						for(x in item){
							var i = item[x];
							itemHtml += shop.header.quickViewOrder.build1Order(i);
						}
						jQuery("#orderListUnuser").html(itemHtml);
						jQuery("#numOrders").html(shop.header.conf.numOrderI);
						
						if(cb) cb();
						if(shop.header.conf.numOrderI >= 4){
							jQuery('#orderListUnuser').jScrollPane();
						}
						shop.header.actionDisplay.order = 1;
					}
				}
			);
		},
		displayListOrdernew: function(cb){
			if(shop.header.conf.numOrderI > 0){
				if(shop.header.actionDisplay.order == 0){
					shop.header.quickViewOrder.buildOrderUnuser2(cb);
				}
				else{
					if(cb) cb();
					if(shop.header.conf.numOrderI >= 5){
						jQuery('#orderListUnuser').jScrollPane();
					}
				}
			}
			else{
				shop.header.actionDisplay.showing = 0;
				jQuery(".noticeOrderUnuser").html('Không có đơn hàng nào.').removeClass("Success").addClass("bookMarkErr");
				jQuery(".noticebuidOrder").removeClass("bookMarkArrSuccess").addClass("bookMarkArrErr");
				jQuery(".divNoticeOrder").show();
				setTimeout(function(){jQuery(".divNoticeOrder").hide();}, 1000);
			}
		}
    },
	wishList:{
		remove:function(obj,type,event){
			var ids = [];
			if(type==1){
				ids[ids.length] = obj.getAttribute('idDelete');
			}else if(type==2){
				jQuery(".v7dele").each(function(){
					ids[ids.length] = obj.getAttribute('idDelete');
				});
			}
			if(ids.length > 0){
				shop.header.actionDisplay.clearMouseClick(event);

				shop.ajax_popup('act=customer&code=removeWishList',"POST",{id:ids},
					function(j){
						var item = j.i;
						var n = 0;
						for(x in item){
							jQuery('#perItemBookMark'+item[x]).remove();
							n++;
						}
						shop.header.conf.numItemWish = shop.header.conf.numItemWish-n;
						
						if(shop.header.conf.numItemWish > 0){
							jQuery(".numOrders").html(shop.header.conf.numItemWish);
							jQuery(".v7likeheader span").html(shop.header.conf.numItemWish);
							jQuery(".v7likeheader span").css("display","inline-block");
							if(shop.header.conf.numItemWish >= 5){
								jQuery('#itemBookListItem').jScrollPane();
							}
						}
						else{
							jQuery(".v7likeheader span").css("display","none");
							jQuery('.ctrlMenu').hide();
						}
				});
			}
		},
		addWishLish: function(item_id){
			// San pham nhieu gia thi hien thi popup chon 1 loai
			var isMPrice = -1;
			$.ajax({
				url: 'ajax.php?act=item&code=getInfo',
				type: 'post',
				dataType: 'json',
				async: false,
				data: {id: item_id},
				success: function(obj) {
					if (obj.err == 0) {
						var item = obj.item;
						var arrPriceObject = item.extra;
						//console.log(item);
						if (arrPriceObject.length > 1) {
							isMPrice = 1;
							// Chon 1 loai trong nhieu gia
							var extra_html = '';
							var extra = arrPriceObject;
							for(var i=0;i<extra.length;i++){
								extra_html += shop.join
								('<div class="'+(i%2==0?'bgBuyPop':'bgBuyPopOdd')+'">')
									('<div class="contentBuyPop fl">')
										('<div class="newTitle">'+extra[i].price_title+'</div>')
										('<div class="detailBuyPop">Giá gốc <b>'+shop.numberFormat(extra[i].price, 0, '', '.')+'đ</b> - Giảm <strong>'+shop.numberFormat(extra[i].price_promotion, 0, '', '.')+'%</strong> - Tiết kiệm <strong>'+shop.numberFormat(extra[i].price_save_money, 0, '', '.')+'đ</strong></div>')
									('</div>')
									('<div class="fr">')
										('<a href="javascript:void(0)" class="buyPopBlock markPopBlock" onclick="shop.header.wishList.addItem(' + item.id + ', '+extra[i].price_id+')"><span><span>Giá <b>'+shop.numberFormat(extra[i].price_save, 0, '', '.')+'đ</b></span></span></a>')
										('<div class="c"></div>')
									('</div>')
									('<div class="c"></div>')
								('</div>')();
							}
							var html = shop.popupSite('cart-extra', 'Chọn thích', '<div class="content" style="padding:20px">'+extra_html+'</div>');
				
							shop.show_overlay_popup('cart-extra','Chọn thích',html,{
								background: {
									'background-color' : 'transparent'
								},
								border: {
									'background-color' : 'transparent',
									'padding' : '0px'
								},
								title: {
									'display' : 'none'
								},
								content: {
									'padding' : '0px',
									'width'   : '650px',
									'font-size': '12px'
								}
							});
						} else {
							isMPrice = 0;
						}
					}
				}
			});
			if (isMPrice == 0) {
				shop.header.wishList.addItem(item_id, 0);
			}
		},
		
		addItem: function(item_id, price_id) {
			shop.hide_popup('cart-extra');
			shop.ajax_popup('act=customer&code=addWishList','post',{item_id:item_id, price_id: price_id},
			function(j){
				if(j.err == 0){
					shop.header.conf.numItemWish ++;
					if(shop.header.actionDisplay.wishList == 0){
						shop.header.wishList.drawListItem();
					}

					var item = shop.header.wishList.drawItem(j.i);
					if(jQuery('#itemBookListItem').children(".jspContainer").children().is('.jspPane')==true){
						jQuery('#itemBookListItem .jspPane').prepend(item);
					}else{
						jQuery('#itemBookListItem').prepend(item);
					}
					if(shop.header.conf.numItemWish >= 5){
						jQuery('#itemBookListItem').jScrollPane();
					}
					jQuery(".numOrders").html(shop.header.conf.numItemWish);
					jQuery(".v7likeheader span").html(shop.header.conf.numItemWish).show();
					jQuery(".noticeBookMark").html(j.msg).removeClass("bookMarkErr").addClass("bookMarkSuccess");
					jQuery(".noticeBookMarkArr").removeClass("bookMarkArrErr").addClass("bookMarkArrSuccess");
					jQuery(".divNoticeBookMark").show();
					setTimeout(function(){jQuery(".divNoticeBookMark").hide();}, 1000);
				}
				else{
					jQuery(".noticeBookMark").html(j.msg).removeClass("bookMarkSuccess").addClass("bookMarkErr");
					jQuery(".noticeBookMarkArr").removeClass("bookMarkArrSuccess").addClass("bookMarkArrErr");
					jQuery(".divNoticeBookMark").show();
					setTimeout(function(){jQuery(".divNoticeBookMark").hide();}, 1000);
				}
			});
		},
		viewwishList: function(cb){
			if(shop.header.conf.numItemWish > 0){
				if(shop.header.actionDisplay.wishList == 0){
					shop.header.wishList.drawListItem(cb);
				}
				else{
					if(cb) cb();
					if(shop.header.conf.numItemWish >= 5){
						jQuery('#itemBookListItem').jScrollPane();
					}
				}
			}
			else{
				shop.header.actionDisplay.showing = 0;
				jQuery(".noticeBookMark").html('Bạn chưa thích sản phẩm nào.').removeClass("bookMarkSuccess").addClass("bookMarkErr");
				jQuery(".noticeBookMarkArr").removeClass("bookMarkArrSuccess").addClass("bookMarkArrErr");
				jQuery(".divNoticeBookMark").show();
				setTimeout(function(){jQuery(".divNoticeBookMark").hide();}, 1000);
			}
		},
		drawListItem:function(cb){
			shop.ajax_popup('act=customer&code=getWishList',"POST",{},
				function(j){
					if(j.err == 0){
						var item = j.i, itemHtml = '', count = 0, i;
						for(x in item){
							i = item[x];
							count ++;
							itemHtml += shop.header.wishList.drawItem(i, count == shop.header.conf.numItemWish);
						}
						jQuery("#itemBookListItem").html(itemHtml);
						jQuery("#numBookMark").html(shop.header.conf.numItemWish);
						
						if(cb) cb();
						if(shop.header.conf.numItemWish >= 5){
							jQuery('#itemBookListItem').jScrollPane();
						}
						shop.header.actionDisplay.wishList = 1;
					}
				}
			);
		},
		drawItem:function(i, last){
			var itemHtml = shop.join
			('<div class="perItemBookMark" id="perItemBookMark'+i.i+'"'+(last?' style="border:0"':'')+' onmouseover="shop.header.wishList.viewDelete('+i.id+')" onMouseOut="shop.header.wishList.viewDelete('+i.id+')">')
				('<div class="fl itemBookImg m0"><a href="'+i.l+'"><img src="'+i.img+'" width="82" height="82" /></a></div>')
				('<div class="fl ordersInfo">')
					('<div style="height:16px;overflow:hidden;font-size:13px"><b><a href="'+i.l+'" style="color:#000">'+i.t+'</a></b></div><div class="fr" style="margin-top:-15px;margin-right:-15px"><a id="delete'+i.id+'" href="javascript:void(0)" class="v7dele hidden" idDelete="'+i.i+'" onclick="shop.header.wishList.remove(this,1,event)"><img src="style/images/mua-chung-vn.gif" width="20" height="20"/></a></div>')
					('<div><div class="itemBookPrice mTop5 fl">Giá: <b>'+i.p+'</b></div><div class="v7typeproduct fl v7proTypeSmall mTop5  mLeft20" style="'+(!i.freeShip?'color: #555':'')+'">'+(i.freeShip?'Freeship':(i.type==1?'Giao phiếu':'Giao hàng'))+'</div><div class="c"></div></div>')
					('<div class="itemBookPrice mTop5"> Đã mua <b>'+i.b+'</b></div>')
					('<div class="fl mTop5"><a href="javascript:void(0)"  onclick="shop.cart.addItem('+i.id+','+i.s+','+i.e+','+i.b+','+i.bneed+')" class="'+((i.r<=0 || i.e==0)?'v7buynewhet':'v7buynew')+'"><img src="style/images/mua-chung-vn.gif" width="87" height="27"/></a></div>'+(i.hv==''?'':'<div class="itemBookPrice mTop10 '+(i.hv=='EndBuy'?'v7hang':'v7jsLike')+' fr "> '+(i.hv=='EndBuy'?' <span>Còn '+ i.title_hv +' '+ i.u +' </span>':'<div class="v6Timer v7TimeNow" >'+i.title_hv+'</div>'))+'</div>')
					('<div class="c"></div>')
				('</div>')
				('<div class="c"></div>')
			('</div><script type="text/javascript">shop.product.init('+i.id+','+i.s+','+i.e+','+i.b+','+i.bneed+',"'+i.ev+'",185,"'+i.u+'",false,'+i.is_end+');</script>')();
			return itemHtml;
		},
		viewDelete:function(id){
			if(jQuery('#delete'+id).hasClass('hidden')){
				jQuery('#delete'+id).removeClass('hidden');
			}else{
				jQuery('#delete'+id).addClass('hidden');
			}
		}
	},
	sale:{
		key: 'saleOff',
		open:function(){
			if(shop.cookie.get(shop.header.sale.key) == ''){jQuery('.blockSaleOff').show()};
		},
		close:function(){
			shop.cookie.set(shop.header.sale.key, 'oh yes', 86400, '/');
			jQuery('.blockSaleOff').slideUp();
		}
	},
	focusPass:{
		focus:function(obj){
			var p = jQuery(obj).parent();
			jQuery('#customer_password', p).css({width: "146px"}).removeClass('hidden').focus();
			jQuery('#customer_password_txt', p).css({width: "0px"}).addClass('hidden');
		},
		blur:function(obj){
			if(obj.value == ''){
				var p = jQuery(obj).parent();
				jQuery('#customer_password', p).css({width: "0px"}).addClass('hidden');
				jQuery('#customer_password_txt', p).css({width: "146px"}).removeClass('hidden');
			}
		}
	},
	menuCustomer:function(login){
		if(IS_CUSTOMER_LOGIN == 0){
			jQuery('.headerInfo').hover(
				function(){//hover
					var cl = jQuery(this).hasClass('regBut') ? 'headerInfoHover2' : 'headerInfoHover';
					jQuery(this).addClass(cl);
				},
				function(){
					var cl = jQuery(this).hasClass('regBut') ? 'headerInfoHover2' : 'headerInfoHover';
					jQuery(this).removeClass(cl);
				}
			);
		}else{
			//xu ly chuoi de ko bi nhay xuong dong
			jQuery('.headerInfo').each(function(){
				var width = jQuery('a.btProfile', this).width(), ie = 10, padding = 24, anchor = 15;
				ie = (shop.is_ie7() || shop.is_ie8() || shop.is_ie6()) ? ie : 0;
				jQuery('a.btProfile', this).css("width", width+ie);
				//xu ly khi hover
				jQuery(this).hover(
					function(){//hover
						jQuery('.anchor').hide();
						jQuery('.headerGoldInfo').hide();
						jQuery(this).addClass('headerInfoActive').css("width", width+padding+ie);
					},
					function(){
						jQuery('.anchor').show();
						jQuery('.headerGoldInfo').show();
						jQuery(this).addClass('headerInfoActive').css("width", width+padding+ie+anchor);
						jQuery(this).removeClass('headerInfoActive');
					}
				).click(function(){
					jQuery(this).removeClass('headerInfoActive');
				});
			});
		}
	},
	menuPlaza:function(){
		var timeOut = 50,
		w = jQuery('.menuPlaza').width(),
		zIcon = jQuery('#plazaC').width() + 30; //padding left, right 15px
		w = -(w - zIcon)/2;
		jQuery('.menuPlaza').css('right', w+'px');

		jQuery('#plazaC').hover(
			function(){
				clearTimeout(shop.header.conf.timer);
				shop.header.conf.timer = setTimeout(function(){
					if(!jQuery('#plazaC').hasClass('buttonDealactive')){
						jQuery('#plazaC').addClass('buttonDealactive');
						jQuery('.menuPlaza').show();
						jQuery('.menuPlazaAnchor').show();
						jQuery('.menuPlaza').hover(
							function(){
								clearTimeout(shop.header.conf.timer);
								if(!jQuery('#plazaC').hasClass('buttonDealactive')){
									jQuery('#plazaC').addClass('buttonDealactive');
									jQuery('.menuPlaza').show();
									jQuery('.menuPlazaAnchor').show();
								}
							},function(){
								clearTimeout(shop.header.conf.timer);
								shop.header.conf.timer = setTimeout(function(){
									jQuery('#plazaC').removeClass('buttonDealactive');
									jQuery('.menuPlaza').hide();
									jQuery('.menuPlazaAnchor').hide();
								}, timeOut);
							}
						);
					}
				}, timeOut);
			},
			function(){
				clearTimeout(shop.header.conf.timer);
				shop.header.conf.timer = setTimeout(function(){
					jQuery('#plazaC').removeClass('buttonDealactive');
					jQuery('.menuPlaza').hide();
					jQuery('.menuPlazaAnchor').hide();
				}, timeOut);
			}
		);
	},
	menuCatClick: function(){
		jQuery('.headerFloat .content').slideToggle();
		if(jQuery('.topCat').hasClass('topCatHover')){
			jQuery('.topCat').removeClass('topCatHover')
		}else{
			jQuery('.topCat').addClass('topCatHover')
		}
	},
	menuCat: function(){
		var timeOut = 50;
		jQuery('.headerFloat .title').hover(
			function(){
				clearTimeout(shop.header.conf.timer);
				shop.header.conf.timer = setTimeout(function(){
					if(!jQuery('.topCat').hasClass('topCatHover')){
						jQuery('.topCat').removeClass('oneBoder');
						jQuery('.topCat').addClass('topCatHover');
						jQuery('.headerFloat .content').hover(
						function(){
							clearTimeout(shop.header.conf.timer);
							if(!jQuery('.topCat').hasClass('topCatHover')){
								jQuery('.topCat').removeClass('oneBoder');
								jQuery('.topCat').addClass('topCatHover');
							}
						},function(){
							clearTimeout(shop.header.conf.timer);
							shop.header.conf.timer = setTimeout(function(){
								jQuery('.topCat').addClass('oneBoder');
								jQuery('.topCat').removeClass('topCatHover');
							}, timeOut);
						});
					}
				}, timeOut);
			},
			function(){
				clearTimeout(shop.header.conf.timer);
				shop.header.conf.timer = setTimeout(function(){
					jQuery('.topCat').addClass('oneBoder');
					jQuery('.topCat').removeClass('topCatHover');
				}, timeOut);
			}
		);
	},
	//floatAction:function(){
	//	jQuery('body').append(shop.join
	//	('<div class="cmdFloat">')
	//		('<a href="'+BASE_URL+'trang-lien-he.html" class="btContact" rel="nofollow"></a>')
	//		('<a href="'+BASE_URL+'trang-cau-hoi-thuong-gap.html" class="btHelp mTop5" rel="nofollow"></a>')
	//	('</div>')());
	//	shop.header.floatActionTop();
	//},
	//floatActionTop:function(){
	//	var h=jQuery('.cmdFloat').height(), wHeight = jQuery(window).height();
	//	jQuery('.cmdFloat').css('top', (wHeight-h)/2);
	//},
	city:{
		conf:{
			city:0,
			safe:'',
			city_cookie:'cityMC'
		},
		menuCity:function(obj, over){
			if(over){
				jQuery(obj).addClass('headerCityOver');
				jQuery('.content',obj).removeClass('hidden');
			}else{
				jQuery('.content',obj).addClass('hidden');
				jQuery(obj).removeClass('headerCityOver');
			}
		},
		cityPopSelect:function(city_id){
			jQuery('#popCityID').val(city_id);
			jQuery('.popCityValue').html(city_list[city_id].title);
			jQuery('.popCityList').addClass('hidden');
		},
		reSetupCity:function(id){
			var cityArr = eval("(" + shop.header.conf.city + ')'),
			html = '',
			def = null;
			id = id == 0 ? shop.cookie.get(shop.header.city.conf.city_cookie) : id;
			if(id > 0){
				for(var i=0;i<cityArr.length;i++) {
					if(cityArr[i].i != 0){
						if(cityArr[i].i == id){
							def = cityArr[i];
						}else{
							html += '<a href="javascript:void(0);" onclick="shop.header.city.setCity('+cityArr[i].i+',\''+cityArr[i].s+'\')"'+( (i == cityArr.length-2) ? ' id="noBoder"' : '')+'>'+cityArr[i].t+'</a>';
						}
					}
				}
				if(def){
					jQuery('.currentBg').html(def.t).attr('id', id);
					jQuery('.mainSublist').html(html);
				}
			}
		},
		start:function(){
			var city = shop.cookie.get(shop.header.city.conf.city_cookie);
			if(city == '' || city == 0){
				if(IS_CUSTOMER_LOGIN == 1 || IS_MOBILE_MODE == 1){
					//neu da dang nhap thi kiem tra tinh thanh, neu ko co thi mac dinh la Ha Noi
					city = (CUSTOMER_PROVINCE && CUSTOMER_PROVINCE > 0) ? CUSTOMER_PROVINCE : 22;
					if(isNaN(city)){
						city = 22;
					}
					shop.cookie.set(shop.header.city.conf.city_cookie, city, 86400*30, '/');
					location.reload();
					return;
				}
				if(shop.header.ads.conf.email != 1){
					shop.show_overlay_popup('popcityemail', '', shop.header.theme.popupCity(),
					{
						background: {'background-color' : 'transparent'},
						border: {
							'background-color' : 'transparent',
							'padding' : '0px'
						},
						title: {'display' : 'none'},
						content: {
							'padding' : '0px',
							'width' : '431px',
							'height': '233px'
						},
						esc:false
					});
				}
			}
		},
		setCity:function(id,safe_title){
			if(IS_CUSTOMER_LOGIN){
				shop.header.city.redirect(id, safe_title);
			}else{
				shop.header.city.conf.city = id;
				shop.header.city.conf.safe = safe_title;
				//chuyen sang nhap email
				var city = shop.cookie.get(shop.header.city.conf.city_cookie);
				if(city == '' || city == 0){
					shop.header.city.start();
				}else{
					shop.header.city.redirect(id, safe_title);
				}
			}
		},
		redirect:function(id, safe_title){
			shop.cookie.set(shop.header.city.conf.city_cookie, id, 86400*30, '/');
			if(query_string == '?' || query_string.indexOf(escape('province=')) != -1){
				//neu o trang chu thi redirect ve dung tinh thanh
				if(shop.is_ie6()){
					setTimeout(function(){window.location = BASE_URL + safe_title}, 0);
				}else{
					window.location.href = BASE_URL + safe_title;
				}
			}else{
				window.location.reload(); // neu dang o 1 trang nao do thi reload lai
			}
		},
		finish:function(){
			var city = jQuery('#popCityID').val(),
			cityArr = eval("(" + shop.header.conf.city + ')');
			if(city == 0){
				alert('Quý khách vui lòng chọn Tỉnh/Thành phố');
			}else{
				for(var i=0;i<cityArr.length;i++) {
					if(cityArr[i].i == city){
						shop.cookie.set(shop.header.city.conf.city_cookie, city, 86400*30, '/');
						shop.cookie.set('showRegEmail', 'not', 86400*365, '/');
						shop.header.city.redirect(city, cityArr[i].s);
						return;
					}
				}
				alert("Tỉnh thành quý khách chọn không hợp lệ");
			}
		}
	},
	email:{
		start:function(){
			jQuery('body').prepend(shop.header.theme.htmlRegMail());
			jQuery('#RegEmail').jNice();
			shop.fix_png('.fixPNG');
			if(shop.cookie.get('showRegEmail') != ''){
				jQuery('#formRegMail').hide();
			};
			shop.enter('#sub-email', function(){shop.header.email.registerCity()});
		},
		hideFormEmail:function() {
			var form = '#formRegMail';
			jQuery(form).slideToggle('slow',function () {
				if(jQuery(form).is(':hidden') == true){
					shop.cookie.set('showRegEmail', 'not', 86400*365, '/');
				}
			});
		},
		registerCity:function(id) {
			id = id ? id : 'sub-email';
			var email = shop.get_ele(id);
			if(email){
				if(shop.util_trim(email.value) == ''){
					alert('Chưa nhập Email');
					email.select();
					email.focus();
					return;
				}else if(!shop.is_email(email.value)){
					alert('Email không hợp lệ');
					email.select();
					email.focus();
					return;
				}else {
					shop.show_overlay_popup('regCity', 'Chọn tỉnh/thành phố',
						shop.header.theme.htmlRegCity('regCity', 'Chọn tỉnh/thành phố'),
						{
							background: {
								'background-color' : 'transparent'
							},
							border: {
								'background-color' : 'transparent',
								'padding' : '0px'
							},
							title: {'display' : 'none'},
							content: {
								'padding' : '0px',
								'width' : '400px',
								'font-size': '12px',
								'color': '#000'
							}
						});
				}
			}
			
		},
		registerEmail: function(obj){
			var email = shop.get_ele('sub-email'),
			ids = '';
			if(email != ''){
				jQuery('.popupSubCity').each(function(){
					if(jQuery(this).hasClass('btSubcityCheck')){
						ids += this.id+',';
					}
				});
				if(ids == ''){
					alert('Xin Quý khách vui lòng chọn tỉnh thành!');
				}else{
					shop.ajax_popup('act=cart&code=register-email',"POST",{sub_email:email.value,sub_city:ids},
					function (j) {
						shop.hide_overlay_popup('regCity');
						if (j.err == 0) {
							shop.cookie.set('showRegEmail', 'not', 86400*365, '/');
							jQuery('#formRegMail').slideUp('slow');
							email.value = '';
							
							//them doan do dang ki email vao
							if(RD_TOOLS == 1){
								_MA.subscribe({
									sitekey	: 'mc',
									email	: email
								});
							}
						} else {
							email.select();
							email.focus();
							jQuery(obj).click(function(){
								shop.header.email.registerEmail(this);
							});
						}
						alert(j.msg);
					},
					{
						loading:function(){
							jQuery(obj).click(function(){});
						}
					});
				}
			}else{
				shop.hide_overlay_popup('regCity');
				email.select();
				email.focus();
				alert('Quý khách vui lòng nhập thông tin Email');
			}
		},
		clickButton:function(obj){
			obj = jQuery(obj);
			if(obj.hasClass('btSubcityCheck')){
			  obj.removeClass('btSubcityCheck');
			}else{
			  obj.addClass('btSubcityCheck');
			}
		}
	},
	faq:{
		conf:{
			type:0,
			arrType:['fb_pro','fb_error'],
			arrTitle:['Thắc mắc về sản phẩm','Thông báo lỗi'],
			id:0,
			title:''
		},
		go:function(id){
			var div = shop.get_ele('productItem'+id);
			if(div){
				shop.header.faq.conf.id = id;
                                shop.header.faq.conf.title = jQuery('#productItem'+id+' .titleBoxName').html();
				shop.header.faq.conf.type = 0;
				
				shop.show_overlay_popup('feedback', 'Yêu cầu hỗ trợ từ MuaChung',
				shop.header.theme.faq('feedback', 'Yêu cầu hỗ trợ từ MuaChung'),
				{
					background: {
						'background-color' : 'transparent'
					},
					border: {
						'background-color' : 'transparent',
						'padding' : '0px'
					},
					title: {'display' : 'none'},
					content: {
						'padding' : '0px',
						'width' : '710px',
						'font-size': '12px',
						'color': '#545454'
					}
				});
			}
		},
		change:function(type){
			if(shop.is_exists(shop.header.faq.conf.arrType[type])){
				var now_id = shop.header.faq.conf.arrType[type];
				//change type
				shop.header.faq.conf.type = type;
				//change title
				jQuery('#fb_form_title').html(shop.header.faq.conf.arrTitle[type]);
				//change button
				jQuery('.fb_bt').each(function(){
					jQuery(this).removeClass(this.id+'_active');
					if(this.id == now_id){
						jQuery(this).addClass(this.id+'_active');
					}
				});
			}
		},
		submit:function(){
			var data = {
				id: shop.header.faq.conf.id,
				type: shop.header.faq.conf.type,
				title: shop.util_trim(jQuery('#fb_title').val()),
				content: shop.util_trim(jQuery('#fb_content').val()),
				email: IS_CUSTOMER_LOGIN <= 0 ? shop.util_trim(jQuery('#fb_email').val()) : ''
			};
			
			if(data.title == '' || data.title.length < 10){
				shop.error.set('#fb_title', 'Tiêu đề phải lớn hơn 10 kí tự', 310, '#fb_form');return;
			}else if(data.content == '' || data.content.length < 50){
				shop.error.close('#fb_title', '#fb_form');
				shop.error.set('#fb_content', 'Nội dung quá ngắn!!! Quý khách vui lòng cung cấp thêm thông tin cho MuaChung', 310, '#fb_form');return;
			}else if(IS_CUSTOMER_LOGIN <= 0 && !shop.is_email(data.email)){
				shop.error.close('#fb_title', '#fb_form');
				shop.error.close('#fb_content', '#fb_form');
				shop.error.set('#fb_email', 'Email không hợp lệ!!!', 310, '#fb_form');return;
			}
			data.content = encodeURIComponent(data.content);
			
			shop.ajax_popup('act=feedback&code=report',"POST",data,
			function (j) {
				if(j.err == -1){
					switch(j.ctrl){
						case 'title':
							shop.error.set('#fb_title', 'Tiêu đề phải lớn hơn 10 kí tự', 310, '#fb_form');
							break;
						case 'content':
							shop.error.set('#fb_content', 'Nội dung quá ngắn!!! Quý khách vui lòng cung cấp thêm thông tin cho MuaChung', 310, '#fb_form');
							break;
						case 'email':
							shop.error.set('#fb_email', 'Email không hợp lệ!!!', 310, '#fb_form');
							break;
						case 'item':
							alert('Hệ thống không tìm thấy thông tin sản phẩm\nQuý khách vui lòng thực hiện lại thao tác.');
							shop.hide_overlay_popup('feedback');
							break;
					}
				}else{
					shop.hide_overlay_popup('feedback');
					shop.show_popup_message('<b>Ý kiến của quý khách đã được MuaChung tiếp nhận.</b><br /><br />MuaChung sẽ hồi đáp Quý khách trong thời gian sớm nhất qua Email.', 'Góp ý thành công', 1, 500);
				}
			});
		}
	},
	ads:{
		conf:{email:0,key:'check_email_from_ads'},
		init:function(){
			if(IS_CUSTOMER_LOGIN == 1 || IS_MOBILE_MODE == 1){
				shop.cookie.set(shop.header.ads.conf.key, 0, 86400*365, '/');
			}else{
				var email_check = shop.cookie.get(shop.header.ads.conf.key);
				if(email_check == 1){
					shop.header.ads.conf.email = 1;
					shop.header.ads.start();
				}
			}
		},
		start:function(){
			shop.show_overlay_popup('popcityemail', '', shop.header.theme.popupCity2(),
			{
				background: {'background-color' : 'transparent'},
				border: {
					'background-color' : 'transparent',
					'padding' : '0px'
				},
				title: {'display' : 'none'},
				content: {
					'padding' : '0px',
					'width' : '726px'
				},
				release:function(){
					shop.enter('#popCityEmail', shop.header.ads.finish);
					jQuery('.missYouNice').jNice();
				},
				esc:false
			});
		},
		finish:function(){
			var email = jQuery('#popCityEmail').val(),
			city = jQuery('#popCityID').val();
			if(city == 0){
				alert('Quý khách vui lòng chọn Tỉnh/Thành phố');
			}else if(email == ''){
				alert('Quý khách vui lòng nhập thông tin Email');
				jQuery('#popCityEmail').focus();
			}else if(!shop.is_email(email)){
				alert('Email không hợp lệ');
				jQuery('#popCityEmail').focus();
			}else{
				shop.ajax_popup('act=cart&code=add-email',"POST",{sub_email:email,sub_city:city},
				function (j) {
					shop.hide_overlay_popup('popcityemail');
					if (j.err == 0) {
						shop.cookie.set(shop.header.city.conf.city_cookie, city, 86400*30, '/');
						shop.cookie.set('showRegEmail', 'not', 86400*365, '/');
						shop.cookie.set(shop.header.ads.conf.key, 0, 86400*365, '/');
						if(j.safe != ''){
							var url = BASE_URL + j.safe;
							if(shop.is_ie6()){
								setTimeout(function(){ window.location = url }, 0);
							}else{
								window.location.href = url;
							}
						}else{
							location.reload();
						}
					} else {
						jQuery('.bt', jQuery('.formCity')).show();
						Query('#popCityEmail').select().focus();
						alert(j.msg);
					}
				},
				{
					loading:function(){
						jQuery('.bt', jQuery('.formCity')).hide();
					}
				});
			}
		},
		openNewLogin:function(){
			if(IS_CUSTOMER_LOGIN){
				alert('Quý khách đã đăng nhập thành công!');
			}else{
				shop.customer.login.conf.cb = shop.header.ads.completeLogin;
				shop.hide_overlay_popup('popcityemail');
				shop.customer.login.show();
			}
		},
		completeLogin:function(data){
			var city_safe = 'ha-noi', city = 22, url = '';
			if(data.city_safe_name && data.city_id){
				city_safe = data.city_safe_name;
				city = data.city_id;
			}
			shop.cookie.set(shop.header.city.conf.city_cookie, city, 86400*30, '/');
			shop.cookie.set('showRegEmail', 'not', 86400*365, '/');
			shop.cookie.set(shop.header.ads.conf.key, 0, 86400*365, '/');
			if(data.safe){
				url = BASE_URL + city_safe;
				if(shop.is_ie6()){
					setTimeout(function(){ window.location = url }, 0);
				}else{
					window.location.href = url;
				}
			}else{
				location.reload();
			}
		}
	},
	theme:{
		popupCity:function(){
			var html_city = '',
			cityArr = eval("(" + shop.header.conf.city + ')');
			for(var i=0;i<cityArr.length;i++) {
				if(cityArr[i].i != 0){
					html_city += '<a href="javascript:shop.header.city.cityPopSelect('+cityArr[i].i+')"'+((i==cityArr.length-2)?' id="noBoder"':'')+'>'+cityArr[i].t+'</a>';
				}
			}
			return shop.join
			('<div id="popupTQ" class="popupCity">')
				('<div class="popupTQ_bg_email"></div>')
				('<div class="popupTQ_c_email">')
					('<div class="formCity">')
						('<div class="popCityID" onmouseout="jQuery(\'.popCityList\').addClass(\'hidden\')" onmouseover="jQuery(\'.popCityList\').removeClass(\'hidden\')">')
							('<input type="hidden" id="popCityID" value="" />')
							('<div class="popCityList hidden">'+html_city+'</div>')
							('<div class="popCityValue">Chọn Tỉnh/Thành phố</div>')
						('</div>')
						('<input type="button" class="bt fl" value="" onclick="shop.header.city.finish()" />')
						('<div class="c"></div>')
					('</div>')
				('</div>')
			('</div>')();
		},
		popupCity2:function(){
			var html_city = '',
			cityArr = eval("(" + shop.header.conf.city + ')'),
			now_city = shop.cookie.get(shop.header.city.conf.city_cookie);
			for(x in cityArr) {
				if(cityArr[x].i != 0){
					html_city += '<option value="'+cityArr[x].i+'"'+(cityArr[x].i==now_city?' selected="selected"':'')+'>'+cityArr[x].t+'</option>';
				}
			}
			return shop.join
			('<div id="popupAdsEmail"><div id="popupTQ" class="popupCity">')
				('<div class="popupTQ_bg_email"></div>')
				('<div class="popupTQ_c_email">')
					('<div class="formCity">')
						('<input type="text" id="popCityEmail" class="txt fl" value="Email của bạn" title="Email của bạn" onblur="if(this.value==\'\') this.value=this.title" onfocus="if(this.value==this.title) this.value=\'\';" />')
						('<div class="popCityID"><form class="missYouNice"><select id="popCityID">')
							('<option value="0">Thành Phố</option>'+html_city)
						('</select></form></div>')
						('<input type="button" class="bt fl" value="" onclick="shop.header.ads.finish()" />')
						('<div class="c"></div>')
						('<div class="plogin">')
							('<a href="javascript:void(0)" onclick="shop.header.ads.openNewLogin()" title="Bấm vào đây để đăng nhập"></a>')
						('</div>')
					('</div>')
				('</div>')
			('</div></div>')();
		},
		htmlRegMail:function(){
			return shop.join
			('<div id="formRegMail">')
				('<div class="regContent">')
					('<div class="text fl fixPNG"><b>Đăng ký nhận email thông báo giảm giá</b></div>')
					('<div class="bgSubscribeEmail fl">')
						('<input type="text" name="email" id="sub-email" value="Nhập email của bạn" onfocus="javascript:if(this.value == \'Nhập email của bạn\') this.value=\'\';" onblur="javascript:if(this.value == \'\')this.value=\'Nhập email của bạn\';"/>')
					('</div>')
					('<a href="javascript:void(0)" onclick="shop.header.email.registerCity()" class="bt_send_email"></a>')
					('<a href="javascript:void(0)" onclick="shop.header.email.hideFormEmail()" class="bt_hide_email">Ẩn [ x ]</a>')
				('</div>')
			('</div>')();
		},
		htmlRegCity: function(id, title) {
			var html_city = '',
			cityArr = eval("(" + shop.header.conf.city + ')'),
			now_city = shop.cookie.get(shop.header.city.conf.city_cookie);
			
			for(var i=0;i<cityArr.length;i++) {
				if(cityArr[i].i != 0){
					html_city += shop.join
					('<tr><td>')
						('<a href="javascript:void(0)" onclick="shop.header.email.clickButton(this)" class="popupSubCity btSubcity mTop10'+(cityArr[i].i==now_city?' btSubcityCheck':'')+'" id="'+cityArr[i].i+'"><span><span>'+cityArr[i].t+'</span></span></a>')
					('</td></tr>')();
				}
			}
			
			return shop.popupSite(id, title, shop.join
			('<div class="content" style="padding:15px 20px">')
				('<div style="font-size:14px;font-weight:bold">Bạn muốn nhận Email thông báo sản phẩm mới ở Tỉnh/Thành phố nào ?</div>')
				('<div style="padding:0 0 0 25px">')
					('<table cellpadding="0" cellspacing="0" border="0" width="100%">')
						('<tr>'+ html_city +'</tr>')
						('<tr><td align="center">')
							('<div style="background:#e3e3e3;height:1px;margin:15px 0 10px;overflow:hidden"></div>')
							('<a id="fr" class="blueButton mLeft10" onclick="shop.header.email.registerEmail(this)" href="javascript:void(0)"><span><span>Hoàn thành</span></span></a>')
						('</td></tr>')
					('</table>')
				('</div>')
			('</div>')());
		},
		faq:function(id, title){
			return shop.popupSite(id, title, shop.join
			('<div id="faq">')
				('<div class="title">')
					('<div id="fb_pro_title"><div>Sản phẩm:</div><div class="c"></div>')
						('<div class="fl"><b>&lsquo;&lsquo;</b></div>')
						('<div class="pro_title fl">'+shop.header.faq.conf.title+'<b>&sbquo;&sbquo;</b></div>')
						('<div class="c"></div>')
					('</div>')
				('</div>')
				('<div class="content">')
					('<div class="cleft">')
						('<a href="javascript:void(0)" onclick="shop.header.faq.change(0)" class="fb_bt fb_pro fb_pro_active" id="fb_pro"><span class="icon"></span><span class="fb_arrow"></span>')
							('<span class="txt"><b>Thắc mắc</b><br /><br />Nhấn vào đây để gửi thắc mắc về sản phẩm</span>')
							('<div class="c"></div>')
						('</a>')
						('<a href="javascript:void(0)" onclick="shop.header.faq.change(1)" class="fb_bt fb_error" id="fb_error"><span class="icon"></span><span class="fb_arrow"></span>')
							('<span class="txt"><b>Thông báo lỗi</b><br /><br />Nhấn vào đây nếu bạn phát hiện lỗi</span>')
							('<div class="c"></div>')
						('</a>')
						('<div class="c"></div>')
					('</div>')
					('<div class="cright" id="fb_form">')
						('<div id="fb_form_title">'+shop.header.faq.conf.arrTitle[shop.header.faq.conf.type]+'</div>')
						('<div id="cError"></div>')
						('<div class="mTop10"><input type="text" id="fb_title" title="Tiêu đề" value="Tiêu đề" onblur="if(this.value==\'\') this.value=this.title;" onfocus="if(this.value==this.title) this.value=\'\';" /></div>')
						('<div class="mTop10"><textarea id="fb_content" onblur="if(this.value==\'\') this.value=this.title;" onfocus="if(this.value==this.title) this.value=\'\';" title="Nội dung">Nội dung</textarea></div>')
						(IS_CUSTOMER_LOGIN <= 0 ? '<div class="mTop10"><input type="text" id="fb_email" title="Email (sẽ được bảo mật)" value="Email (sẽ được bảo mật)" onblur="if(this.value==\'\') this.value=this.title;" onfocus="if(this.value==this.title) this.value=\'\';" /></div>' : ' ')
						('<div class="mt28"><a href="javascript:void(0)" onclick="shop.header.faq.submit()" class="blueButton" id="fr"><span><span>Gửi cho MuaChung</span></span></a></div>')
					('</div>')
					('<div class="c"></div>')
				('</div>')
			('</div>')());
		}
	}
};
